#!/bin/bash

#--system auto config variables(don't modify!)--
SUDO=""

function check_root_permisson()
{
    if [ ${UID} -eq 0 ]; then
        SUDO=""
    else
        SUDO=sudo
    fi
}

function make_all()
{
    make all -C binlock
    make all -C ckey
    make all -C dict
    make all -C scripts
}

function make_install()
{
    make install -C binlock
    make install -C ckey
    make install -C dict
    rm -rf ${HOME}/.oh-my-zsh
    cp -rf oh-my-zsh ${HOME}/.oh-my-zsh
    cp -rf ./oh-my-zsh/templates/zshrc.zsh-template $(HOME)/.zshrc
    sudo apt-get install -y zsh
    make install -C scripts
    cd ./fpermission ; bash ./install.sh
}

function make_clean()
{
	make clean -C binlock
	make clean -C ckey 
	make clean -C dict
	make clean -C scripts
}

function make_distclean()
{
	make distclean -C binlock
	make distclean -C ckey
	make distclean -C dict
	make distclean -C scripts
}

function make_uninstall()
{
	make uninstall -C binlock
	make uninstall -C ckey
	make uninstall -C dict
	rm -rf ${HOME}/.oh-my-zsh
	make uninstall -C scripts
}

function exec_install()
{
    dirtop=`pwd`
    dirname="$1"
    shell="$2"
    initscript="$3"
    if [ "${1}" = "" ]; then
        dirname="."
    fi
    fulldir=${dirtop}/${dirname}
    echo "fulldir = ${fulldir}"
    cd ${fulldir} ; ${shell} ./${initscript} ; cd ${dirtop}
}

# 判断用户权限,需要root用户权限
check_root_permisson
exec_install "ubuntu-init" "bash" "base.sh"
exec_install "ubuntu-init" "bash" "network.sh"
exec_install "ubuntu-init" "bash" "kernel.sh"
exec_install "ubuntu-init" "bash" "media.sh"
exec_install "binlock" "bash" "install.sh"
exec_install "ckey" "bash" "install.sh"
exec_install "fpermission" "bash" "install.sh"
exec_install "" "bash" "oh-my-zsh.sh"
exec_install "scripts" "bash" "install.sh"

